package net.takela.common.security.service;

import net.takela.common.security.model.AuthUser;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.AuthorityUtils;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;

import java.util.List;


public class UserDetailServiceImpl implements UserDetailsService {
    
    /**
     * 
     */
    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        List<GrantedAuthority> auths = AuthorityUtils.commaSeparatedStringToAuthorityList("1");
        AuthUser user = new AuthUser("baboy", new BCryptPasswordEncoder().encode("123"), auths);
        user.setUid(1236L);
        //TODO: 读取ACL权限配置
        return user;
    }
    /**
     * 
     */
    public UserDetails loadUserByUid(Long uid){
        List<GrantedAuthority> auths = AuthorityUtils.commaSeparatedStringToAuthorityList("1");
        AuthUser user = new AuthUser("baboy", new BCryptPasswordEncoder().encode("123"), auths);
        user.setUid(1236L);
        //TODO: 读取ACL权限配置
        return user;
    }
}
